<?php
if(!defined('BZ_XTBLOG')){
    exit('Access Denied!');
}
class user{
	  function user_name($uid,$nid=''){
	  	global $db,$w,$wappced;
	  	 $usera=$db->get_one('user'," `uid` = '$uid'",'`name`,`nameys`');
	  	 $hynamee='<font color="'.$usera[nameys].'">'.Bingz_html($usera[name]).'</font>';
       if($nid){$hynamee=Bingz_html($usera[name]);}
	     return $hynamee;
	  }
	  function user_sex($uid,$nid=''){
	  	global $db,$w;
	  	 $usera=$db->get_one('user'," `uid` = '$uid'",'`sex`');
	  	 if($usera[sex] == '1'){
	  	 	  $sex='<i class="iconFemale"></i>';
	  	 	  $sexx='女生';
       }else{
          $sex='<i class="iconMale"></i>';
          $sexx='男生';
       }
       if($nid){$sex=$sexx;}
	     return $sex;
	  }
	  function user_zhuangtai($uid,$nid=''){
	  	global $db,$w;
	  	 $usera=$db->get_one('user'," `uid` = '$uid'",'`sex`');
	  	 if($usera[user_zx] == '5'){
	  	 	  $zhuangtai='<font color="#ff0000">在线</font>';
       }else{
          $zhuangtai='<font color="#000000">离线</font>';
       }
	     return $zhuangtai;
	  }
	  function user_tx($uid){
	  	global $db;
	  	 $usera=$db->get_one('user'," `uid` = '$uid'",'`show`');
       if($usera['show']){
            $hytx=$usera['show'];
       }else{
            $hytx='images/user/show.png';
       }
	     return $hytx;
	  }
	  function user_rzts($uid,$nid=''){
	  	global $db,$w;
	  	 $usera=$db->get_one('user'," `uid` = '$uid'",'``');
	  	 if($usera[email_d] == '1'){
	  	 	  $email='<img src="images/user/yx.jpg">';
       }else{
          $email='<img src="images/user/yx_1.jpg">';
       }
	  	 if($usera[mobile_d] == '1'){
	  	 	  $mobile='<img src="images/user/sj.jpg">';
       }else{
          $mobile='<img src="images/user/sj_1.jpg">';
       }
	  	 if($usera[qq_d] == '1'){
	  	 	  $qq='<img src="images/user/qq.jpg">';
       }else{
          $qq='<img src="images/user/qq_1.jpg">';
       }
	  	 if($usera[smz_d]){
	  	 	  $smz='<img src="images/user/smz.jpg">';
       }else{
          $smz='<img src="images/user/smz_1.jpg">';
       }
	     return $smz.$qq.$mobile.$email;
	  }
	  function user_qm($uid){
	  	global $db,$ubb;
	  	 $usera=$db->get_one('user'," `uid` = '$uid'",'`user_qm`');
	  	 if(!$usera['user_qm']){$usera['user_qm']='还没有签名！';}
	     return Bingz_html($usera['user_qm']);
	  }
		function user_yhz($uid,$name=''){
	  	global $db,$time;
	  	$user=$db->get_one('user'," `uid` = '$uid'",'`user_qx`');
	  	$usersms=$db->get_one('user_qxz',"`type` = '1' and `id` = '$user[user_qx]' ",'');
	  	if($user[user_qx] == '0'){
	  		 $useradmin='普通会员';
	    }else{
	    	 $useradmin='<font color="#'.$usersms['name_ys'].'">'.$usersms['name'].'</font>';
	    }
		  return $useradmin;
	  }
		function user_teoo($uid,$name=''){
	  	global $db,$time;
	  	$user=$db->get_one('user'," `uid` = '$uid'",'`jifen`');
	  	$usersms=$db->get_one('user_qxz',"`type` = '0' and `jifen` < '$user[jifen]' ORDER BY `jifen` DESC LIMIT 0 , 1",'');
	    if($name){
	        $useradmin=$usersms[$name];
	    }else{
	      	$useradmin='<font color="#'.$usersms['name_ys'].'">'.$usersms['name'].'</font>';
	    }
		  return $useradmin;
	  }
		function user_qx($type,$fid='',$uid=''){
	  	global $db,$user_uid,$time;
	  	 $user=$db->get_one('user'," `uid` = '$uid'",'`user_qx`');
	     $usersms=$db->get_one('user_qxz',"`id` = '$user[user_qx]' ",'');
	  	 if($user[time_c] > '0' && $user[time_c] < $time ){
   	        $db->update('user'," `user_qx` = '0', `time_c` = '0'"," `uid` = '$user[uid]'");
   	        $user[user_qx]='0';
   	   }
      if($type == 'forum'){
	  	   $forum=$db->get_one('forum'," `id` = '$fid'",'`fid`');
	  	   $forumlt=$db->get_one('forum_class'," `id` = '$forum[cid]'",'`fid`');
         $forum_ltbz=$db->get_one('forum_admin'," `uid` = '$uid' AND `fid` = '$forum[cid]' AND `type` = '0'",'');//版
         $forum_ltqz=$db->get_one('forum_admin'," `uid` = '$uid' AND `fid` = '$forumlt[fid]' AND `type` = '1'",'');//区
         if($forum_ltbz && $usersms[qxid] == '5'){
         	  $qx='5';
         }
         if($forum_ltqz && $usersms[qxid] == '5' ){
         	  $qx='6';
         }
         if($usersms[qxid] == '7'){
         	  $qx='7';
         }
         if($usersms[qxid] > '7' && $usersms[qxid] < '10'){
         	  $qx='8';
         }
         if($usersms[qxid] == '10'){
         	  $qx='10';
         }
      }else{
         if($usersms[qxid] > '6' && $usersms[qxid] < '10'){
         	  $qx='8';
         }
         if($usersms[qxid] == '10'){
         	  $qx='10';
         }
      }
		  return $qx;
	  }
function user_password($uid,$pass,$tst=''){
	  	global $db,$w,$ip,$time,$_config;
	    $pwssm=user_mm($pass);
	    $pwss=md5($time);
		  $db->update('user',array( 'pass' => $pwssm, 'pwss'=> $pwss)," `uid` ='$uid'");
	    $usera=$db->get_one('user'," `uid` = '$uid'",'`email`,`email_d`,`mobile`,`mobile_d`');
	    if(Bingz_config('email_set_editpwd') == '1'){
	   	  $email_set_reg_title=Bingz_config('email_set_editpwd_title');
        $email_set_reg_body=Bingz_config('email_set_editpwd_body');
        $email_set_reg_body=str_replace('{userpass}',$passa,$email_set_reg_body);
	   	  Bingz_email_smtp_post($email,$email_set_reg_title,$email_set_reg_body);
	   }
	   if(Bingz_config('sms_set_editpwd') == '1'){
        $email_set_reg_body=Bingz_config('sms_set_editpwd_body');
        $email_set_reg_body=str_replace('{userpass}',$passa,$email_set_reg_body);
	   	  Bingz_sms_post($userrmb[mobile],$email_set_reg_body);
	   }
	   if(!$tst){$tst='你好！你成功修改新密码！';}
	   Bingz_message_post('0',$uid,$tst);
	return $mmmm;
}
function user_reg($name,$phone='',$email='',$passa,$mobile_d='0'){
	  	global $db,$w,$ip,$time,$_config;
	    $pass=user_mm($passa);
      $pwss=md5($time);
      $user_config_reg_xinxi=Bingz_config('user_config_reg_xinxi');
      $user_config_reg_money=Bingz_config('user_config_reg_money');
      $user_config_reg_jifen=Bingz_config('user_config_reg_jifen');
      $user_config_reg_yeobi=Bingz_config('user_config_reg_yeobi');
  if($db->insert('user',array('uid' => 'NULL', 'name' => $name,'nameys' => '#000000','smz' => '', 'email' => $email, 'mobile' => $phone,'mobile_d' => $mobile_d, 'pass'=> $pass, 'pwss'=> $pwss, 'time_a'=> $time, 'time_b'=> $time, 'yeobi'=> $user_config_reg_yeobi,'money'=> $user_config_reg_money, 'jifen'=> $user_config_reg_jifen, 'ip_at'=> $ip ))){
  	 $uid=$db->insert_id();
	   if(Bingz_config('email_set_reg') == '1'){
	   	  $email_set_reg_title=Bingz_config('email_set_reg_title');
        $email_set_reg_body=Bingz_config('email_set_reg_body');
        $email_set_reg_body=str_replace('{username}',$name,$email_set_reg_body);
        $email_set_reg_body=str_replace('{userpass}',$passa,$email_set_reg_body);
	   	  Bingz_email_smtp_post($email,$email_set_reg_title,$email_set_reg_body);
	   }
	   if(Bingz_config('sms_set_reg') == '1'){
        $email_set_reg_body=Bingz_config('sms_set_reg_body');
        $email_set_reg_body=str_replace('{username}',$name,$email_set_reg_body);
        $email_set_reg_body=str_replace('{userpass}',$passa,$email_set_reg_body);
	   	  Bingz_sms_post($phone,$email_set_reg_body);
	   }
	   setcookie('user_login',$pwss);
	   setcookie('user_ip',$ip);
  	 Bingz_message_post('0',$uid,$user_config_reg_xinxi);
  }
	return $uid;
}
function user_login($value,$passa,$ssjj='',$zx=''){
	  	global $db,$w,$time,$_config,$time,$ip,$time_jt,$wzxx_gold_name;
	    $paaa     =user_mm($passa);
	    $fdyz     =date("is");
	    if(Bingz_config('system_config_login_dlsj')){
	    	$timesjw=time()+(Bingz_config('system_config_login_dlsj')*86400);
	    }
	  if($userdl=$db->get_one('user'," `uid` ='$value' and  `pass` ='$paaa' ",'')){
	     	  setcookie('user_login',$userdl[pwss],$timesjw);
	        setcookie('user_ip',$ip,$timesjw);
	        $ip_dz=ip_address($ip);
		      $db->update('user',array('user_zx' => 5 , 'time_a' => $time,'ip' => $ip ,'ip_dz' => $ip_dz,'user_banben' => $banben ),"`uid` ='$userdl[uid]'");
		      $db->insert('user_dl',array('id' => 'NULL', 'type' => 0, 'uid' => $userdl['uid'], 'uip' => $ip, 'uip_dz'=> $ip_dz , 'zhuangt'=> '成功' , 'time_a'=> $time));	
  	      $mmmm=$userdl[uid];
    }elseif($userdl=$db->get_one('user'," `name` ='$value' and  `pass` ='$paaa' ",'')){
	     	  setcookie('user_login',$userdl[pwss],$timesjw);
	        setcookie('user_ip',$ip,$timesjw);
	        $ip_dz=ip_address($ip);
          $db->update('user',array('user_zx' => 5 , 'time_a' => $time,'ip' => $ip ,'ip_dz' => $ip_dz,'user_banben' => $banben ),"`uid` ='$userdl[uid]'");
		      $db->insert('user_dl',array('id' => 'NULL', 'type' => 0, 'uid' => $userdl['uid'], 'uip' => $ip, 'uip_dz'=> $ip_dz , 'zhuangt'=> '成功' , 'time_a'=> $time));	
  	      $mmmm=$userdl[uid];
    }elseif($userdl=$db->get_one('user'," `mobile` ='$value' and  `pass` ='$paaa' ",'')){
	     	  setcookie('user_login',$userdl[pwss],$timesjw);
	        setcookie('user_ip',$ip,$timesjw);
	        $ip_dz=ip_address($ip);
		      $db->update('user',array('user_zx' => 5 , 'time_a' => $time,'ip' => $ip ,'ip_dz' => $ip_dz,'user_banben' => $banben ),"`uid` ='$userdl[uid]'");
		      $db->insert('user_dl',array('id' => 'NULL', 'type' => 0, 'uid' => $userdl['uid'], 'uip' => $ip, 'uip_dz'=> $ip_dz , 'zhuangt'=> '成功' , 'time_a'=> $time));	
  	      $mmmm=$userdl[uid];
	  }
	  return $mmmm;
}
}
$user_class= new user();
?>